﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class ST10DeviceManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST10DeviceManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
            //开启定时器任务
            //DispatcherTimer dispatcherTimer = new DispatcherTimer();
            //dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            //dispatcherTimer.Tick += OnTick;
            //dispatcherTimer.Start();


        }

        //private void OnTick(object? sender, EventArgs e)
        //{
        //    ST10PressureCurrentValue = OtherDevicePLCToPC_Global.testData2s[1].CurrentValue;
        //    ST10PressureResult = OtherDevicePLCToPC_Global.testData2s[1].Result[0];
           
        //}

        private void InitParam()
        {
            ST10HoldingTime = TestPressure_Global.testPressures[1].HoldingTime;
            ST10HoldingPressure = SetPressure_Global.pressures[1];
        
        }



        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST10");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST10View, param);
        }




        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "ST10HoldingTime":
                    TestPressure_Global.testPressures[1].HoldingTime = ST10HoldingTime;
                    break;

                case "ST10HoldingPressure":
                    SetPressure_Global.pressures[1] = ST10HoldingPressure;
                    break;
              
                default:
                    break;
            }
        }

        #endregion

        #region 属性


        

        private short _ST10HoldingTime;
        public short ST10HoldingTime
        {
            get { return _ST10HoldingTime; }
            set { SetProperty(ref _ST10HoldingTime, value); }
        }

        private float _ST10HoldingPressure;
        public float ST10HoldingPressure
        {
            get { return _ST10HoldingPressure; }
            set { SetProperty(ref _ST10HoldingPressure, value); }
        }

        #endregion
    }
}
